package com.dragon.loan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.dragon.app.marvel.core.dto.MarvelAttachmentDTO;
import com.dragon.app.marvel2.NewMarvelCoreService;
import com.dragon.common.entity.search.Searchable;
import com.dragon.common.repository.mybatis.paginator.domain.PageBounds;
import com.dragon.common.service.BaseService;
import com.dragon.common.utils.PropertiesLoader;
import com.dragon.loan.entity.CmAttachment;
import com.dragon.loan.repository.CmAttachmentRepository;
import com.fintech.common.constant.MarvelURLConstant;

@Service
public class CmAttachmentService extends BaseService<CmAttachment, Long> implements CmAttachmentIDragonService {

	private static final String ATTACHMENT_TYPE_ID_CARD = "A";

	@Autowired
	private AcLoanApplyInfoServiceImpl acLoanApplyInfoService;
	@Autowired
	private CmAttachmentRepository cmAttachmentRepository;
	@Autowired
	private NewMarvelCoreService newMarvelCoreService;
	@Autowired
	private GetCommonParamIService getCommonParamIService;

	@Override
	public List<CmAttachment> queryAttachments(String loanId, String atmtType) {
		return queryAttachments(loanId, new String[] {atmtType});
	}
	
	public List<CmAttachment> queryAttachments(String loanId, String... atmtType) {
		Searchable searchable = new Searchable();
		searchable.addSearchParam("loanId_eq", loanId);
		if (atmtType != null) {
			searchable.addSearchParam("atmtType_in", atmtType);
		}
		searchable.addSearchParam("status_eq", "A0");
		return selectList(searchable, new PageBounds());
	}


	@Override
	public boolean insertMsg(List<CmAttachment> cmAttachments) {
		try {
			for (CmAttachment cmAttachment : cmAttachments) {
				cmAttachmentRepository.insert(cmAttachment);
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	
}
